import { axios } from '@/utils/request'
import Vue from "vue";
import fileDownload from "js-file-download";
import {downFile} from "@/api/fileDownload";

/**
 * 发票汇总确认-查询汇总确认信息
 * @param data
 * @returns {AxiosPromise}
 */
export function queryIscInfomationPage(data) {
    return axios({
        url: "/vatoutinv/vmsIscInformation/pageIscConfirm",
        method:'post' ,
        data
    })
}
/**
 * 查询发票信息
 * @param data
 * @returns {AxiosPromise}
 */
export function pageInvoice(data) {
    return axios({
        url: "/vatoutinv/vmsIscInformation/pageInvoice",
        method:'post' ,
        data
    })
}
/**
 * 导出
 * @param data
 * @returns {AxiosPromise}
 */
export function exportExecl(parameter,method) {
    return downFile('/vatoutinv/vmsIscInformation/exportExecl', parameter,method).then((data) => {
        if (!data || data.size === 0) {
            Vue.prototype['$message'].warning('文件下载失败')
            return
        }

        var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
        var contentDisposition = decodeURI(data.headers['content-disposition'])
        var result = patt.exec(contentDisposition)


        try {
            var fileName = result[1]
            fileName = fileName.replace(/\"/g, '')
        } catch (error) {
            return Vue.prototype['$message'].warning('文件下载失败')
        }
        if(!fileName) return Vue.prototype['$message'].warning('文件下载失败')

        fileDownload(data.data,fileName)
    })
}
/**
 * cancelIsc取消汇总确认
 * @param data
 * @returns {AxiosPromise}
 */
export function cancelIsc(data) {
    return axios({
        url: "/vatoutinv/vmsIscInformation/cancelIsc",
        method:'post' ,
        data
    })
}
/**
 * 上传汇总确认信息
 *
 * @param data
 * @returns {AxiosPromise}
 */
export function uploadIsc(data) {
    return axios({
        url: "/vatoutinv/vmsIscInformation/uploadIsc",
        method:'post' ,
        data
    })
}
